<template>
	<!-- 兑换订单 -->
	<view class="exchangeorderr_wp">
		<view class="e_nav">
			<view :class="{'e_nav_active':active==0}" @click="navTap(0)">待付款</view>
			<view :class="{'e_nav_active':active==1}" @click="navTap(1)">待兑换</view>
			<view :class="{'e_nav_active':active==3}" @click="navTap(3)">已完成</view>
			<view :class="{'e_nav_active':active==4}" @click="navTap(4)">售后</view>
		</view>
		<view class="e_list">
			<view class="e_item" v-for="item in list" :key="item.id"
				@click="$navTo('/pages/business/myexchangedetails?id='+item.id)">
				<view class="e_itee_head">
					<view>订单编号：{{item.ordersn}}</view>
					<view>{{item.statusName}}</view>
				</view>
				<view class="e_itee_body" v-for="iitem in item.goodsList" :key="iitem.id">
					<image :src="iitem.thumb" ></image>
					<view class="e_itee_name">
						<view class="e_itee_title">{{iitem.goodstitle}}</view>
						<view class="e_itee_price"><text>{{iitem.realprice}}元</text><text>×{{iitem.total}}</text>
						</view>
					</view>
				</view>
				<view class="e_itee_money">
					<text>总价</text><text>{{item.price}}</text><text>元</text>
				</view>
				<view class="e_buttons">
					<text v-if="active==0" @click.stop="cancelOrder($event,item.id)">取消订单</text>
					<text v-if="active==1" @click.stop="refundTap($event,item.id,1)">申请退款</text>

					<text v-if="active==4" @click.stop="refundTap($event,item.id,2)">查看售后</text>
					<text v-if="active==3" @click.stop="refundTap($event,item.id,3)">评价</text>
					<text class="e_pay" v-if="active==0" @click.stop="payTap($event,item.id)">立即支付</text>
				</view>
			</view>
		</view>
		<view class="loading_message">
			<image v-if="isloading" src="/static/business/loading.gif" ></image>
			<text v-if="isempty">到底了~</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active: 1,

				list: [],
				page: 0,

				stoploading: false,
				isloading: false,
				isempty: false,
			}
		},
		onReachBottom() {
			this.getList();
		},
		onLoad(option) {
			this.active = option.status ? option.status : this.active;
			this.getList();
		},
		methods: {
			cancelOrder(e, v) {
				e.stopPropagation();
				this.$axios('Op/cancel', 'POST', 'order', {
					orderid: v
				}).then(res => {
					if (res.data.code == 200) {
						this.$api.msg('已取消订单！');
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/business/myorder?status=0'
							})
						}, 1000)
					}
				})
			},
			refundTap(e, v, idx) {
				e.stopPropagation();
				let url = idx == 1 ? '/pages/order/Customer?id=' + v : '/pages/order/AfterSales?id=' + v;
				url = idx == 3 ? '/pages/order/evaluate?id=' + v : url;
				this.$navTo(url);
			},
			payTap(e, v) {
				e.stopPropagation();
				uni.redirectTo({
					url: '/pages/money/pay?orderid=' + v
				})
			},
			getList() {
				this.page += 1;
				if (this.stoploading) return;
				this.stoploading = true;
				this.isloading = true;
				this.$axios('Lists/zorder', 'POST', 'order', {
					page: this.page,
					status: this.active
				}).then(res => {
					this.isloading = false;
					if (res.data.code == 200) {
						let length = res.data.data.list.length;
						this.list = [...this.list,...res.data.data.list];
						this.isempty = length <= 0 ? true : false;
						this.stoploading = length <= 0 ? true : false;
					}
				})
			},
			navTap(e) {
				if (this.active == e) return;
				this.active = e;
				this.page = 0;
				this.list = [];
				this.stoploading = false;
				this.isempty = false;
				this.getList();
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
		color: $font-color-dark;
		padding-bottom: 130upx;
	}

	.e_nav {
		background-color: #fff;
		display: flex;
		align-items: center;
		line-height: 100upx;
		position: fixed;
		width: 100%;
		z-index: 100;
	}

	.e_nav view {
		flex: 1;
		text-align: center;
		font-size: $font-base;
		position: relative;
	}

	.e_nav_active:after {
		content: '';
		border-bottom: 3px $base-color solid;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		bottom: 20upx;
		width: 40upx;
	}

	.e_list {
		padding-top: 100upx;
		overflow: hidden;
	}

	.e_item {
		background-color: #fff;
		border-radius: 10upx;
		margin: 20upx 20upx 0;
		padding: 20upx;

	}

	.e_itee_head,
	.e_itee_body,
	.e_itee_price {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.e_itee_head view:nth-of-type(2) {
		color: $base-color;
	}

	.e_itee_body {
		border-bottom: 1px hsl(0, 0%, 87%) solid;
		align-items: flex-start;
		padding: 20upx 0;
	}

	.e_itee_body image {
		border-radius: 10upx;
		width: 140upx;
		height: 140upx;
	}

	.e_itee_name {
		flex: 1;
		padding-left: 20upx;
		line-height: 35upx;
	}

	.e_itee_title {
		height: 68upx;
		overflow: hidden;
	}

	.e_itee_price {
		padding-top: 35upx;
	}

	.e_itee_price text:nth-of-type(2) {
		font-size: 34upx;
	}

	.e_itee_money {
		padding: 30upx 0;
		text-align: right;
	}

	.e_itee_money text:nth-of-type(2) {
		margin-left: 10upx;
		color: $base-color;
	}

	.e_itee_money text:nth-of-type(3) {
		color: $base-color;
		font-size: 20upx;
	}

	.e_buttons {
		text-align: right;
	}

	.e_buttons text {
		border: 1px hsl(0, 0%, 87%) solid;
		border-radius: 40upx;
		display: inline-block;
		line-height: 60upx;
		margin-left: 20upx;
		text-align: center;
		width: 190upx;
	}

	.e_buttons .e_pay {
		border-color: $base-color;
		color: $base-color;
	}

	.loading_message {
		color: #0062CC;
		padding: 20upx;
		text-align: center;
	}

	.loading_message image {
		height: 50upx;
		width: 50upx;
	}
</style>
